﻿using System;
using System.Collections;
using System.Data;
using CE.Database;
using CE.Security;

/// <summary>
/// Summary description for CarScriptDB
/// </summary>
namespace CE.CarInsurance
{
    public class CarScriptDB
    {
        public Int64 InsertUpdate(CarScript caruserprofile)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarScriptInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CarScriptID", caruserprofile.CarScriptID);
            _sPara.Add("@CECarId", caruserprofile.CECarId);
            _sPara.Add("@RefCEUserId", caruserprofile.RefCEUserId);
            _sPara.Add("@InsuranceType", caruserprofile.InsuranceType);
            _sPara.Add("@CoverageCommenceDate", caruserprofile.CoverageCommenceDate);
            _sPara.Add("@CurrentInsurer", caruserprofile.CurrentInsurer);
            _sPara.Add("@SumInsured", caruserprofile.SumInsured);
            _sPara.Add("@GarageType", caruserprofile.GarageType);
            _sPara.Add("@NoOfDriver", caruserprofile.NoOfDriver);
            _sPara.Add("@DriverAge1", caruserprofile.DriverAge1);
            _sPara.Add("@DriverAge2", caruserprofile.DriverAge2);
            _sPara.Add("@ProvinceRegistration", caruserprofile.ProvinceRegistration);
            _sPara.Add("@OccupationId", caruserprofile.OccupationId);
            _sPara.Add("@IsClaimLastYear", caruserprofile.IsClaimLastYear);
            _sPara.Add("@CreatedDate", caruserprofile.CreatedDate);
            _sPara.Add("@ModifiedDate", caruserprofile.ModifiedDate);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        //public CarScript GetCarScript(Int64 CECarId)
        //{
        //    MyDatabase _Db = new MyDatabase();
        //    string _spName = "sprocCarScriptSelectSingleItem";
        //    CarScript _result = null;
        //    DataTable _dt;
        //    SortedList _sPara = new SortedList();
        //    _sPara.Add("@CECarId", CECarId);
        //    _dt = _Db.GetDataTableBySP(_spName, _sPara);
        //    if (_dt != null && _dt.Rows.Count > 0)
        //    {
        //        _result = new CarScript();
        //        _result = FillDataRecord(_dt);
        //    }
        //    return _result;
        //}

        private CarScript FillDataRecord(DataTable myDataTable)
        {
            CarScript myCarScript = new CarScript();
            myCarScript.CarScriptID = Convert.ToInt64(myDataTable.Rows[0]["CarScriptID"].ToString());
            myCarScript.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCarScript.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarId"].ToString());
            myCarScript.InsuranceType = Convert.ToInt32(myDataTable.Rows[0]["InsuranceType"].ToString());

            myCarScript.CoverageCommenceDate = myDataTable.Rows[0]["CoverageCommenceDate"].ToString();
            myCarScript.CurrentInsurer = myDataTable.Rows[0]["CurrentInsurer"].ToString();

            myCarScript.SumInsured = Convert.ToInt32(myDataTable.Rows[0]["SumInsured"].ToString());
            myCarScript.GarageType = Convert.ToInt32(myDataTable.Rows[0]["GarageType"].ToString());
            myCarScript.OccupationId = Convert.ToInt32(myDataTable.Rows[0]["OccupationId"].ToString());
            myCarScript.NoOfDriver = Convert.ToInt32(myDataTable.Rows[0]["NoOfDriver"].ToString());
            myCarScript.DriverAge1 = Convert.ToInt32(myDataTable.Rows[0]["DriverAge1"].ToString());
            myCarScript.DriverAge2 = Convert.ToInt32(myDataTable.Rows[0]["DriverAge2"].ToString());
            myCarScript.ProvinceRegistration = myDataTable.Rows[0]["ProvinceRegistration"].ToString();
            myCarScript.IsClaimLastYear = Convert.ToBoolean(myDataTable.Rows[0]["IsClaimLastYear"].ToString());

            return myCarScript;
        }

    }
}
